﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Negocios;

namespace UI
{
    public partial class ManterProgramacao : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            tbDia.Text = "";
            tbMes.Text = "";
            tbAno.Text = "";
            tbMinuto.Text = "";
            tbHora.Text = "";
        }

        protected void tbData_TextChanged(object sender, EventArgs e)
        {

        }

        protected void tbHora_TextChanged(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            ProgramacaoBOMetodos pm = new ProgramacaoBOMetodos();
            ProgramacaoBO po = new ProgramacaoBO();
            if (po.Canal != null)
            {
                po.Canal.Nome = ddlCanal.SelectedValue; 
            }
            int dia = Convert.ToInt32(tbDia.Text);
            int mes = Convert.ToInt32(tbMes.Text);
            int ano = Convert.ToInt32(tbAno.Text);
            int hora = Convert.ToInt32(tbHora.Text);
            int minuto = Convert.ToInt32(tbMinuto.Text);
            po.Data_Hora = new DateTime(ano, mes, dia, hora, minuto, 0);
            if (po.Episodio != null)
            {
                po.Episodio.Nome = ddlEpisodio.SelectedValue; 
            }
            pm.Inserir(po);

        }

        protected void lbAtualizar_Click(object sender, EventArgs e)
        {
            LinkButton lb = (LinkButton)sender;
            DataControlFieldCell celula = (DataControlFieldCell)lb.Parent;
            GridViewRow linha = (GridViewRow)celula.Parent;
            int ID = Convert.ToInt32(linha.Cells[0].Text);

            ProgramacaoBOMetodos pm = new ProgramacaoBOMetodos();
            ProgramacaoBO pBO = new ProgramacaoBO();
            pBO = pm.Consultar(ID);
            tbDia.Text = pBO.Data_Hora.Day.ToString();
            tbMes.Text = pBO.Data_Hora.Month.ToString();
            tbAno.Text = pBO.Data_Hora.Year.ToString();
            tbHora.Text = pBO.Data_Hora.Hour.ToString();
            tbMinuto.Text = pBO.Data_Hora.Minute.ToString();
            ddlCanal.SelectedValue = pBO.Canal.Id.ToString();
            ddlEpisodio.SelectedValue = pBO.Episodio.Id.ToString();
        }
    }
}